package com.wenlin.myproduction.binder;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.wenlin.myproduction.R;
import com.wenlin.myproduction.bean.RecordBean;
import com.wenlin.myproduction.util.Checker;
import com.wenlin.myproduction.util.TypeData;
import com.wenlin.myproduction.util.TypeDataNames;
import com.wenlin.myproduction.util.UI;
import com.wenlin.myproduction.widget.ShuDuView;

import org.greenrobot.eventbus.EventBus;

import me.drakeet.multitype.ItemViewBinder;

public class RecordBinder extends ItemViewBinder<RecordBean, RecordBinder.VH> {


    @NonNull
    @Override
    protected VH onCreateViewHolder(@NonNull LayoutInflater inflater, @NonNull ViewGroup parent) {
        return new VH(inflater.inflate(R.layout.item_record, parent, false));
    }

    @Override
    protected void onBindViewHolder(@NonNull VH holder, @NonNull RecordBean item) {
        String str = "";
        if (Checker.notNull(item.getNumData())) {
            str = "在" + item.getNumData().getPositionNum() + "个空位中设置数字" + item.getNumData().getNum();
        }
        UI.setText(holder.tv, "第" + item.getStep() + "步：" + str);
        holder.sdv.setData(item);
        UI.setOnClickListener(holder.itemView, v -> EventBus.getDefault().post(new TypeData<>(TypeDataNames.resetToRecord, item)));
    }

    static class VH extends RecyclerView.ViewHolder {
        TextView tv;
        ShuDuView sdv;

        public VH(@NonNull View itemView) {
            super(itemView);
            tv = itemView.findViewById(R.id.tv);
            sdv = itemView.findViewById(R.id.sdv);
        }
    }
}
